﻿using UnityEngine;using System.Collections;[RequireComponent (typeof(Collider))]public class Switch : MonoBehaviour {    // Use this for initialization    private bool isContact = false;
    private bool isOn = false;    public Trigger[] Triggers;    void Start () {        }    // Update is called once per frame    void Update() {        if (Input.GetKeyDown(KeyCode.E) && isContact) {            if (Triggers != null) {                foreach (Trigger trigger in Triggers) {                    trigger.Do();                }            }
            isOn = !isOn;
            if (isOn) {
                renderer.material.color = Color.green;
            }
            else {
                renderer.material.color = Color.red;
            }        }    }    void OnTriggerEnter(Collider other) {        if (other.gameObject.tag == "Player") {            isContact = true;        }    }    void OnTriggerExit(Collider other) {        if (other.gameObject.tag == "Player" && isContact) {            isContact = false;        }    }}